<!-- 企业信息审核 -->
<template>
  <div class="home-page-content">
    <h3>企业信息审核</h3>
    <Form :model="formData" ref="FormRef" class="form-reset">
      <Row :gutter="30">
        <Col span="8">
          <CardMain itemName="公司名称">
            <FormItem prop="companyName">
              <Input
                v-model="formData.companyName"
                clearable
                placeholder="请输入公司名称"
              ></Input>
            </FormItem>
          </CardMain>
        </Col>
        <Col span="8">
          <CardMain itemName="证件类型">
            <FormItem prop="companyCardTypeName">
              <CompanySelect
                type="2"
                :companyId.sync="formData.companyCardTypeName"
                :companyChangeId="formData.companyCardTypeName"
                isMargin
              />
            </FormItem>
          </CardMain>
        </Col>
        <Col span="8">
          <CardMain itemName="证件号码">
            <FormItem prop="companyCardNumber">
              <Input
                v-model="formData.companyCardNumber"
                clearable
                placeholder="请输入证件号码"
              ></Input>
            </FormItem>
          </CardMain>
        </Col>
        <Col span="8">
          <CardMain itemName="提交时间">
            <FormItem>
              <DatePicker
                type="datetimerange"
                :value="datetime"
                @on-change="dateChange"
                clearable
                placeholder="请选择时间"
                style="width: 100%"
              ></DatePicker>
            </FormItem>
          </CardMain>
        </Col>
        <Col span="12">
          <CardMain itemName="审核类型">
            <FormItem prop="checkType">
              <Select
                v-model="formData.checkType"
                clearable
                placeholder="审核类型"
                class="company-select"
              >
                <Option value="0">初次审核</Option>
                <Option value="1">变更审核</Option>
              </Select>
              <Input
                v-model="formData.input"
                clearable
                placeholder="搜索关键词"
              ></Input>
            </FormItem>
          </CardMain>
        </Col>
        <Col span="8">
          <CardMain itemName="上级组织">
            <FormItem prop="parentId">
              <CompanySelect
                :companyId.sync="formData.parentId"
                :companyChangeId="formData.parentId"
              />
            </FormItem>
          </CardMain>
        </Col>
        <Col span="16">
          <div class="action-search-btn">
            <Button type="primary" @click="queryList()">查询</Button>
            <Button type="primary" @click="formReset()">重置</Button>
          </div>
        </Col>
        <Col span="24" class="action-table-btn">
          <Button type="primary" @click="batchReview(2)">批量通过</Button>
          <Button type="warning" @click="batchReview(3)">批量拒绝</Button>
        </Col>
      </Row>
    </Form>
    <Row class="main-box">
      <Col span="24">
        <Table
          :columns="columns"
          :data="listData"
          :loading="isLoading"
          @on-selection-change="selectionChange"
        >
          <template slot-scope="{ row }" slot="serviceArea">
            {{ serviceAreaFn(row.serviceArea) }}
          </template>
          <template slot-scope="{ row }" slot="serviceType">
            {{ serviceTypeFn(row.serviceType) }}
          </template>
          <template slot-scope="{ row }" slot="types">
            <Tag type="border" color="primary">{{ row.checkTypeName }}</Tag>
          </template>
          <template slot-scope="{ row, index }" slot="file">
            <ViewImg
              isPreview
              isViewBtn
              isIcon
              errorMsg="证件照片"
              :fileList="row.companyIdFiles"
            ></ViewImg>
          </template>
          <template slot-scope="{ row, index }" slot="action">
            <BtnText type="primary" @BtnClick="handleAction(row, 1)"
              >查看</BtnText
            >
            <BtnText
              type="green"
              v-if="row.auditStatus == 'UnderReview'"
              @BtnClick="handleAction(row, 2)"
              >通过</BtnText
            >
            <BtnText
              type="error"
              v-if="row.auditStatus == 'UnderReview'"
              @BtnClick="handleAction(row, 3)"
              >拒绝</BtnText
            >
          </template>
        </Table>
      </Col>
    </Row>
    <PageAtion
      v-if="total"
      :total="total"
      :size.sync="formData.size"
      :page.sync="formData.page"
      @pageSizeChange="pageSizeChange"
    />
  </div>
</template>

<script type="text/javascript">
import {
  GetCheckCompanyPage, //查询企业信息列表
  GetCheckCompanyInfo, // 企业审核
  CheckCompanylnfo, // 批量审核
} from "@/api/enterpriseInforManage.js";

import { returnStr } from "@/libs/util.js";

export default {
  name: "enterpriseInforExamine",
  components: {},
  data() {
    return {
      formData: {
        companyName: "",
        companyCardNumber: "",
        companyCardTypeName: "",
        startDate: "",
        endDate: "",
        parentId: "",
        parentName: "",
        checkType: "",
        page: 1,
        size: 10,
      },
      columns: [
        {
          type: "selection",
          width: 60,
          align: "center",
        },
        {
          title: "公司名称",
          key: "companyName",
          width: 160,
        },
        {
          title: "证件类型",
          key: "companyCardTypeName",
          width: 120,
        },
        {
          title: "证件号码",
          key: "companyCardNumber",
          width: 120,
        },
        {
          title: "证件照片",
          width: 120,
          slot: "file",
        },
        {
          title: "注册地址",
          key: "companyAddress",
          width: 180,
        },
        {
          title: "业务范围",
          key: "businessRange",
          width: 100,
          tooltip: true,
          ellipsis: true,
        },
        {
          title: "上级组织",
          key: "parentName",
          width: 100,
          tooltip: true,
          ellipsis: true,
        },
        {
          title: "服务地区",
          key: "serviceAreaName",
          width: 200,
          tooltip: true,
          ellipsis: true,
        },
        {
          title: "产业标记",
          key: "serviceTypeName",
          width: 100,
          tooltip: true,
          ellipsis: true,
        },
        {
          title: "提交时间",
          key: "createDateTime",
          width: 180,
        },
        {
          title: "审核类型",
          slot: "types",
          width: 120,
        },
        {
          title: "审核状态",
          key: "auditStatusName",
          width: 100,
        },
        {
          title: "拒绝原因",
          key: "rejectReason",
          width: 100,
        },
        {
          title: "操作",
          slot: "action",
          width: 200,
          align: "center",
          fixed: "right",
        },
      ],
      listData: [],
      total: 0,
      isLoading: false,
      datetime: [],
      checkList: [],
    };
  },
  methods: {
    pageSizeChange() {
      this.getCheckCompanyData();
    },
    queryList() {
      this.formData.page = 1;
      this.getCheckCompanyData();
    },
    formReset() {
      this.formData.page = 1;
      this.formData.size = 10;
      this.formData.companyCardTypeName = "";
      this.formData.startDate = "";
      this.formData.endDate = "";
      this.datetime = [];
      this.$refs.FormRef.resetFields();
      this.getCheckCompanyData();
    },
    async getCheckCompanyData() {
      this.isLoading = true;
      let { data, total } = await GetCheckCompanyPage(this.formData);
      data.forEach((o) => {
        o._disabled = o.auditStatus != "UnderReview";
        o.serviceAreaName = this.serviceAreaFn(o.serviceArea)
        o.serviceTypeName =this.serviceTypeFn(o.serviceType)
      });
      this.isLoading = false;
      this.listData = data;
      this.total = total;
    },
    serviceAreaFn(data) {
      return returnStr(data, "provinceName", "cityName");
    },
    serviceTypeFn(data) {
      return returnStr(data, "serviceTypeName");
    },
    selectionChange(ev) {
      console.log(ev, "2");
      this.checkList = ev;
    },
    dateChange(ev) {
      this.formData.startDate = ev[0];
      this.formData.endDate = ev[1];
    },
    handleAction(row, types) {
      console.log(types, "types");
      if (types == 1) {
        this.$router.push({
          name: "enterpriseDetail",
          query: {
            id: row.id,
          },
        });
        return;
      }
      if (types == 2) {
        this.$Modal.confirm({
          title: "审核通过",
          content: "<p>确定审核通过吗？</p>",
          loading: true,
          onOk: async () => {
            let params = [
              {
                id: row.id,
                auditStatus: 2,
              },
            ];
            let that = this;
            try {
              let data = await GetCheckCompanyInfo(params);
              this.$tips(
                {
                  iconName: "icon_1",
                  text: "审核通过",
                },
                function handleClose(data) {
                  that.getCheckCompanyData();
                }
              );
              this.$Modal.remove();
            } catch (error) {
              this.$Modal.remove();
            }
          },
        });
      }
      if (types == 3) {
        let that = this;
        this.$tips(
          {
            iconName: "icon_2",
            text: "审核已拒绝",
            isArgument: true,
          },
          // 点击确定的按钮回调
          async function handleSubmit(ev, value) {
            console.log("0000");
            if (!value) return that.$Message.error("请输入拒绝理由");
            try {
              let params = [
                {
                  id: row.id,
                  auditStatus: 3,
                  rejectReason: value,
                },
              ];
              let data = await GetCheckCompanyInfo(params);
              ev.remove();
              that.$tips(
                {
                  iconName: "icon_2",
                  text: "审核拒绝",
                },
                function handleClose(data) {
                  that.getCheckCompanyData();
                }
              );
            } catch (error) {
              ev.remove();
            }
          }
        );
      }
    },
    async batchReview(type) {
      let params = [];
      let auditStatus = type;
      let msg = type == 2 ? "审核通过" : "审核拒绝";
      let icon = type == 2 ? "icon_1" : "icon_2";
      let isArgument = type == 2 ? false : true;
      if (!this.checkList.length) {
        return this.$Message.error("请选择需要处理的数据");
      }
      if (type == 2) {
        this.$Modal.confirm({
          title: "审核通过",
          content: "<p>确定审核通过吗？</p>",
          loading: true,
          onOk: async () => {
            let that = this;
            try {
              params = this.checkList.map((o) => {
                return {
                  id: o.id,
                  auditStatus,
                  companyId: o.companyId,
                  companyName: o.companyName,
                  rejectReason: "",
                };
              });
              let data = await GetCheckCompanyInfo(params);
              this.$tips(
                {
                  iconName: "icon_1",
                  text: "审核通过",
                },
                function handleClose(data) {
                  that.getCheckCompanyData();
                }
              );
              this.$Modal.remove();
            } catch (error) {
              this.$Modal.remove();
            }
          },
        });
      }
      if (type == 3) {
        let that = this;
        this.$tips(
          {
            iconName: "icon_2",
            text: "审核已拒绝",
            isArgument: true,
          },
          // 点击确定的按钮回调
          async function handleSubmit(ev, value) {
            try {
              params = that.checkList.map((o) => {
                return {
                  id: o.id,
                  auditStatus,
                  companyId: o.companyId,
                  companyName: o.companyName,
                  rejectReason: value,
                };
              });
              console.log(params);
              if (ev) {
                let data = await GetCheckCompanyInfo(params);
                ev.remove();
                that.$tips(
                  {
                    iconName: "icon_2",
                    text: "审核拒绝",
                  },
                  function handleClose(data) {
                    that.getCheckCompanyData();
                  }
                );
              }
            } catch (error) {
              ev.remove();
            }
          }
        );
      }
    },
  },
  mounted() {
    this.getCheckCompanyData();
  },
};
</script>

<style lang="less" scoped>
.home-index-content {
  h3 {
    font-size: 18px;
  }
}

.company-select {
  margin-right: 10px;
}
</style>
